/**
 *  system.cpp
 *  AwkwardPaint - Engine
 *
 *  Date: 09/08/2013
 *
 *  Language: C++
 *
 *  @author Carl McCaffrey
 *
 */
#include "system.h"

#include "renderer/sprite.h"

void System::Init(HINSTANCE* hInstance, float width, float height)
{
    DebugInit("debug.txt");
    dbg_output->Print("Initializing...\n");

    renderer = new Renderer;
    renderer->Init(hInstance, 1920 / 2, 1080 / 2, false, true);

    dbg_output->Print("Initialization Complete!\n------------------------\n\n");
}

void System::Shutdown(void)
{
    dbg_output->Print("\n------------------------\nShutting Down...\n");

    renderer->Shutdown();
    delete renderer;
    renderer = NULL;

    DebugShutdown();
}

void System::Run(void)
{
    MSG msg;
    bool running = true;

    Sprite hud;
    renderer->CreateSprite(&hud, 0, 1920 / 2, 200 / 2, 1920, 200, 1, 0 * (3.14159 / 180), NULL);
    //hud.SetColor();

    LoadLevel(renderer, "level.txt");

    while(running){
        while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){
			if(msg.message == WM_QUIT){
				running = false;
			}else{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}

        renderer->BeginFrame();

        renderer->DrawSprite(&level->field);
        for(unsigned int i = 0; i < level->bunkers.size(); i++){
            renderer->DrawSprite(&level->bunkers[i].sprite);
        }
        renderer->DrawSprite(&hud);

        renderer->EndFrame();
    }
}
